package org.lanqiao.netctoss.controller.tariff;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.Timestamp;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.lanqiao.netctoss.entity.Tariff;
import org.lanqiao.netctoss.service.impl.TariffServiceImpl;

import com.sun.xml.internal.txw2.Document;

/**
 * Servlet implementation class FeeAddServlet
 */
public class FeeAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FeeAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		//response.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("GBK");
		String name = request.getParameter("name");//资费名称
		int type = Integer.parseInt(request.getParameter("radFeeType"));//资费类型0包月1套餐2计时
		int btime=0;
		float btar=0;
		float dtar=0;
		int state = 0;
		Timestamp ktime = null;
		if(type==0){
			btime = 0;//基本时常
			btar = Integer.parseInt(request.getParameter("btar"));//基本费用
			dtar = 0;//单位费用		
		}
		if(type==1){
			btime = Integer.parseInt(request.getParameter("btime"));//基本时常
			btar = Float.parseFloat(request.getParameter("btar"));//基本费用
			dtar = Float.parseFloat(request.getParameter("dtar"));//单位费用	
		}
		if(type==2){
			btime = 0;//基本时常
			btar = 0;//基本费用
			dtar = Float.parseFloat(request.getParameter("dtar"));//单位费用	
		}
		/*btime = Integer.parseInt(request.getParameter("btime"));//基本时常
		btar = Float.parseFloat(request.getParameter("btar"));//基本费用
		dtar = Float.parseFloat(request.getParameter("dtar"));//基本费用
*/		String comm = request.getParameter("comm");
		/*TariffBuss tariffBuss = new TariffBussImpl();
		boolean b = tariffBuss.insTariff(new Tariff(name,btime,btar,dtar,ktime,state,type,comm));*/
		int i = new TariffServiceImpl().insTariff(new Tariff(name,btime,btar,dtar,ktime,state,type,comm));
		if(i>0){
			PrintWriter out = response.getWriter();
			out.print("<script>alert('添加成功!');window.location.href='../view/fee/fee_add.jsp'</script>");		
			/*RequestDispatcher rd =request.getRequestDispatcher("");
			rd.forward(request, response);*/
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
